package com.example.arithmeticleetcode.leetcode;

/**
 * @program: arithmetic-leetcode
 * @description: 905. 按奇偶排序数组
 * @author: FangZhen
 * @create: 2020-06-08 14:06
 **/
public class Demo26 {

    public static void main(String[] args) {
        int[] A = {3, 1, 2, 4};
        sortArrayByParity(A);
        int[] B = {0, 1};
        sortArrayByParity(B);
    }

    public static int[] sortArrayByParity(int[] A) {
        int[] arr = new int[A.length];
        int j = 0;
        int count = A.length;
        for (int i = 0, len = A.length; i < len; i++) {
            if (A[i] % 2 == 0) {
                arr[j++] = A[i];
                continue;
            }
            arr[--count] = A[i];
        }
        return arr;
    }
}
